package com.dlc.yunguang.net.protocol;

import com.dlc.commonlibrary.utils.LogPlus;
import com.dlc.yunguang.net.bean.LoginBean;
import com.dlc.yunguang.net.bean.MsgBean;
import com.dlc.yunguang.net.bean.NoticeNoreadsBean;
import com.dlc.yunguang.net.bean.NoticeReadBean;
import com.dlc.yunguang.net.bean.RegisterBean;
import com.dlc.yunguang.net.bean.SimpleBean;
import com.dlc.yunguang.net.protocol.base.HttpProtocol;
import com.lzy.okgo.model.HttpParams;
import java.io.File;
import rx.Observable;

/**
 * 用户相关协议，注册登录，设置用户信息之类的
 */
public class UserProto extends HttpProtocol {

    private UserProto() {
    }

    private static class InstanceHolder {
        private static final UserProto sProtocol = new UserProto();
    }

    public static UserProto get() {
        return InstanceHolder.sProtocol;
    }

    /**
     * 1 登录
     *
     * @param account 用户名
     * @param password 密码
     */
    public Observable<LoginBean> login(String account, String password, String error) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("account", account);
        httpParams.put("password", password);
        LogPlus.i("--------username_login--------");
        return rxPost("login", httpParams, LoginBean.class, false, error);
    }

    /**
     * 修改用户资料
     * @param httpParams
     * @return
     */
    public Observable<LoginBean> updateUserInfo(HttpParams httpParams) {
        return rxPost("edit", httpParams, LoginBean.class, true, null);
    }

    /**
     * 修改用户信息
     *
     * @param params
     * @param loginBeanCallback
     * @author kawaimisashi
     */
    public void alterUserMsg(HttpParams params, Callback<LoginBean> loginBeanCallback) {
        post("edit", params, LoginBean.class, true, loginBeanCallback);
    }


    public Observable<LoginBean> alterHead(File file) {
        HttpParams params = new HttpParams();
        //params.put("avatar",file);
        params.put("avatar", file);
        return rxPost("edit", params, LoginBean.class, true, null);
    }


    /**
     * 获取验证码
     *
     * @param account
     * @param Callback
     */
    public void getCheckCode(String account, Callback<SimpleBean> Callback) {
        HttpParams params = new HttpParams();
        params.put("account", account);
        post("sms", params, SimpleBean.class, false, Callback);
    }

    /**
     * 重设密码
     *
     * @param account
     * @param Callback
     */
    public void resetPassword(String account, String password, String sms,
                              Callback<LoginBean> Callback) {
        HttpParams params = new HttpParams();
        params.put("account", account);
        params.put("password", password);
        params.put("sms", sms);
        post("forgot", params, LoginBean.class, false, Callback);
    }

    public void alterHead(File file, Callback<LoginBean> Callback) {
        HttpParams params = new HttpParams();
        //params.put("avatar",file);
        params.put("avatar", file);
        post("edit", params, LoginBean.class, true, Callback);
    }

    public void opinionFeedback(String text, Callback<SimpleBean> Callback) {
        HttpParams params = new HttpParams();
        params.put("title", 1);
        params.put("text", text);
        post("feedback_edit", params, SimpleBean.class, true, Callback);
    }
    public Observable<RegisterBean> register(String code, String error) {
        HttpParams params = new HttpParams();
        params.put("code", code);

        return rxPost("is_registered", params, RegisterBean.class, false, error);
    }
    /**
     * 消息列表
     *
     * @param callback
     */
    public void getMsg(Callback<MsgBean> callback) {
        post("notice", null, MsgBean.class, true, callback);
    }

    public void readMsg(String id, Callback<NoticeReadBean> Callback) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        post("notice_read", params, NoticeReadBean.class, true, Callback);
    }
    public void notice_noreads( Callback<NoticeNoreadsBean> Callback) {
        HttpParams params = new HttpParams();
        post("notice_noreads", params, NoticeNoreadsBean.class, true, Callback);
    }
}
